// const {
// 	db,
// 	dbCmd,
// 	$,
// 	result_success,
// 	result_error,
// 	appletInfoCollection,
// 	shopieCollection,
// 	shopieReportCollection,
// 	userCollection
// } = require('../../common/constants')
// module.exports = async function(params = {}) {
// 	const token = this.getUniIdToken()
// 	if (!token) {
// 		return result_error('登录失效,请重新登录')
// 	}
// 	let payload = await this.uniID.checkToken(token)
// 	if (payload.code) {
// 		return payload
// 	}
// 	let cUser = await userCollection.doc(payload.uid).get()
// 	cUser = cUser.data[0]
// 	//获取当前应用
// 	let appletInfoData = await appletInfoCollection.doc(cUser.app_id).get()
// 	appletInfoData = appletInfoData.data[0]

// 	let queryType = params.queryType
// 	let startDate = params.startDate
// 	let endDate = params.endDate
// 	let startDateTime;
// 	let endDateTime;
// 	let timezone = 8;
// 	let calDateTime = timezone * 60 * 60 * 1000;
// 	if (startDate) {
// 		if (!endDate) {
// 			endDate = startDate
// 		}
// 		startDate = new Date(startDate + ' 00:00:00');
// 		endDate = new Date(endDate + ' 23:59:59');
// 		if (startDate && startDate.toString().indexOf('UTC') > -1) {
// 			startDateTime = startDate.getTime() - calDateTime;
// 			endDateTime = endDate.getTime() - calDateTime;
// 		} else {
// 			startDateTime = startDate.getTime();
// 			endDateTime = endDate.getTime();
// 		}
// 	} else {
// 		let cDate = new Date()
// 		if (cDate && cDate.toString().indexOf('UTC') > -1) {
// 			cDate.setHours(cDate.getHours() + 8)
// 		}
// 		let cYear = cDate.getFullYear();
// 		let cMonth = cDate.getMonth() + 1;
// 		let cDay = cDate.getDate();
// 		startDate = new Date(cYear + "-" + cMonth + "-" + cDay + ' 00:00:00');
// 		endDate = new Date(cYear + "-" + cMonth + "-" + cDay + ' 23:59:59');
// 		if (startDate && startDate.toString().indexOf('UTC') > -1) {
// 			startDateTime = startDate.getTime() - calDateTime;
// 			endDateTime = endDate.getTime() - calDateTime;
// 		} else {
// 			startDateTime = startDate.getTime();
// 			endDateTime = endDate.getTime();
// 		}
// 	}
// 	let qrcode = ''
// 	let gathering = await db.collection('wmzmall-gathering').where({
// 		app_id: appletInfoData._id,
// 		shop_id: appletInfoData._id
// 	}).get()
// 	gathering = gathering.data
// 	if (gathering && gathering.length > 0) {
// 		qrcode = gathering[0].qrcode
// 	}
// 	let rData = {
// 		name: appletInfoData.shop_name,
// 		mobile: appletInfoData.user_name,
// 		qrcode: qrcode,
// 		total_money: 0,
// 		total_count: 0,
// 		customer_count: 0,
// 		recharge_total: 0,
// 		average_money: 0
// 	}
// 	if (!startDateTime || !endDateTime) {
// 		return result_success(rData)
// 	}

// 	let queryShopieTotal = {
// 		app_id: appletInfoData._id,
// 		shop_id: appletInfoData._id,
// 		type: 0,
// 		create_time: dbCmd.gte(startDateTime).and(dbCmd.lte(endDateTime))
// 	};
// 	//交易总金额
// 	let shopieReportTotal = await shopieReportCollection.aggregate().match({
// 		app_id: appletInfoData._id,
// 		shop_id: appletInfoData._id,
// 		date_time: dbCmd.gte(startDateTime).and(dbCmd.lte(endDateTime))
// 	}).group({
// 		_id: '$app_id',
// 		total: $.sum('$money')
// 	}).limit(1000).end();
// 	let total_money = 0
// 	if (shopieReportTotal.data[0] && shopieReportTotal.data[0].total) {
// 		total_money = (shopieReportTotal.data[0].total / 100).toFixed(2)
// 	}
// 	//交易总数
// 	let shopieReportCount = await shopieReportCollection.aggregate().match({
// 		app_id: appletInfoData._id,
// 		shop_id: appletInfoData._id,
// 		date_time: dbCmd.gte(startDateTime).and(dbCmd.lte(endDateTime))
// 	}).group({
// 		_id: '$app_id',
// 		total: $.sum('$pay_count')
// 	}).limit(1000).end();
// 	let total_count = 0
// 	if (shopieReportCount.data[0] && shopieReportCount.data[0].total) {
// 		total_count = shopieReportCount.data[0].total
// 	}

// 	//顾客数
// 	let customerCount = await shopieCollection.aggregate().match(queryShopieTotal).group({
// 		_id: '$creator_id'
// 	}).limit(1000).end();
// 	let customer_count = customerCount.data.length
// 	//储值金额
// 	let queryRechargeTotal = queryShopieTotal
// 	queryRechargeTotal.cate = '充值'
// 	let rechargeTotal = await shopieCollection.aggregate().match(queryRechargeTotal).group({
// 		_id: '$app_id',
// 		total: $.sum('$money')
// 	}).limit(1000).end();
// 	let recharge_total = 0
// 	if (rechargeTotal.data[0] && rechargeTotal.data[0].total) {
// 		recharge_total = (rechargeTotal.data[0].total / 100).toFixed(2)
// 	}
// 	//笔均价
// 	let average_money = (total_money / total_count).toFixed(2)

// 	let report_start_time = '00:00:00'
// 	let report_end_time = '23:59:59'
// 	if (appletInfoData.report_start_time && appletInfoData.report_end_time && appletInfoData.report_end_time !=
// 		'23:59:59') {
// 		report_start_time = appletInfoData.report_start_time
// 		report_end_time = "次日"+appletInfoData.report_end_time  
// 	}
// 	rData = {
// 		name: appletInfoData.shop_name,
// 		mobile: appletInfoData.user_name,
// 		qrcode: qrcode,
// 		total_money: total_money,
// 		total_count: total_count,
// 		customer_count: customer_count,
// 		recharge_total: recharge_total,
// 		average_money: average_money,
// 		report_start_time: report_start_time,
// 		report_end_time: report_end_time
// 	}
// 	return result_success(rData)
// }